/*
 * Steps for coding copy action: (Maintenance Form)
 * 1. create a copy action inherit SimpleActionCopy and implement 5 methods
 * 2. add getDAOClass() in the module delegate class
 * 3. overwrite checkIfFormExists() in the module DAO, --this may not be used
 * 4. overwrite populateForm() in Maint Action
 * 5. JSP add pop up window
 * 6. add getCopyActionClass() in Maint Action
 */

package com.erp.framework.controller.action;

//JRE Classes
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.erp.framework.SimpleConstants;
import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

public abstract class SimpleCopyAction implements SimpleConstants{

    protected abstract LinkedList addCriteriaList(Object obj);

    protected abstract ArrayList addCriterialColumnList(Object obj);

    protected abstract ArrayList addRsltTextList(Object obj);

    protected abstract ArrayList addRsltColumnList(Object obj);

    protected abstract Hashtable addTblParams(Object obj);

    protected String getCompanyCode(Object obj) {

        return null;
    }

    public void showCopyDialog(HttpServletRequest request, String sessionName, String sessionValue, String exclusive,
            String opener) throws Exception {

        try {
            HttpSession session = request.getSession(false);
            User editingUser = (User) session.getAttribute(SimpleConstants.SESSION_USER);
            String compCode = "";

            String tmpCompCode = getCompanyCode(session);
            if (tmpCompCode == null) {
                compCode = editingUser.getCompanyCode();
            } else {
                compCode = tmpCompCode;
            }

            LinkedList criteriaList = addCriteriaList(compCode);
            ArrayList criteriaColumnList = addCriterialColumnList(null);
            ArrayList rsltTextList = addRsltTextList(null);
            ArrayList rsltColumnList = addRsltColumnList(null);
            Hashtable tblParams = addTblParams(session);

            HashMap params = new HashMap();
            params.put(SimpleConstants.SESSION_SESSION_NAME, sessionName);
            params.put(SimpleConstants.SESSION_SESSION_VALUE, sessionValue);
            params.put(SimpleConstants.SESSION_EXCLUSIVE, exclusive);
            params.put(SimpleConstants.SESSION_OPENER_PATH, opener);
            params.put(SimpleConstants.SESSION_CRITERIA_LIST, criteriaList);
            params.put(SimpleConstants.SESSION_CRITERIA_COLUMN_LIST, criteriaColumnList);
            params.put(SimpleConstants.SESSION_RESULT_TEXT_LIST, rsltTextList);
            params.put(SimpleConstants.SESSION_RESULT_COLUMN_LIST, rsltColumnList);
            params.put(SimpleConstants.SESSION_TABLE_PARAMS, tblParams);
            session.setAttribute(SimpleConstants.SESSION_COMMON_SEARCH_PARAMETERS, params);

        } catch (Exception e) {
            Logger.logExceptions(this, e);
            throw e;
        }
    }
}